package com.gopay.common.user.dao.impl;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.gopay.common.base.dao.impl.BaseDAOImpl;
import com.gopay.common.domain.dc.DcUserCardInfo;
import com.gopay.common.user.dao.UserDCInfoDAO;

@Repository("userDCInfoDAO")
public class UserDCInfoDAOImpl extends BaseDAOImpl<DcUserCardInfo, Serializable> implements  UserDCInfoDAO {
	 private static final Logger logger = LoggerFactory.getLogger(UserDCInfoDAOImpl.class);
	
	@Override
	public List<DcUserCardInfo> getDcAuth(String custId) {
		
		//必须是没有解绑并且启用状态的口令卡才能有使用权限
		String hql="from DcUserCardInfo t where t.custId=:custId and " +
				"t.unbundingStat='0' and t.tokenStat='0'";
		 Map<String, Object> param = new HashMap<String, Object>();
	        param.put("custId", custId);      
		 List<DcUserCardInfo> list=this.findByHql(hql, param);
		
		return list;
	}

	@Override
	public int getErrNum(String custId) {
		int num=0;
		String sql="select * from dc_user_card_info  t where t.cust_id='"+custId+"' and " +
				"t.unbunding_stat='0' and t.token_stat='0'";
		List<DcUserCardInfo> list= this.findBySql(sql);
		if(list==null||list.size()==0){
			logger.info("该用户没有绑定和启用动态口令卡");
		}else{
		num=Integer.parseInt(list.get(0).getTokenErrorNum());
		}
		return num;
	}

	@Override
	public void updateErrNum(DcUserCardInfo du) {
		// TODO Auto-generated method stub
		this.update(du);
	}

	@Override
	public List getDcAuthByUserId(String userId) {
		//必须是没有解绑并且启用状态的口令卡才能有使用权限
		String hql="from DcUserCardInfo t where t.userId=:userId and " +
				"t.unbundingStat='0' and t.tokenStat='0'";
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("userId", userId);
		List<DcUserCardInfo> list=this.findByHql(hql, param);

		return list;
	}

}
